package com.doraro.coal.moudle.purch.enums;

import com.baomidou.mybatisplus.core.enums.IEnum;
import lombok.Getter;

/**
 * @author doraro
 * @since 2019-09-30 16:51
 */
@Getter
public enum  PermitStatus  implements IEnum<Integer> {

    /**
     * 采购需求枚举
     */
    DART(0,"草稿"),
    ADUITING(1,"审核中"),
    REJECT(2,"已驳回"),
    PUBLISHED(3,"已发布"),
;
    PermitStatus(Integer value,String desc){
        this.value = value;
        this.desc = desc;
    }

    private Integer value;
    private String desc;
    @Override
    public Integer getValue() {
        return this.value;
    }

    /**
     * 枚举状态机
     * 草稿->草稿 || 审核中
     * 审核中-> 已驳回 || 已发布
     * 已驳回-> 草稿 || 审核中
     * @param to 目标状态
     * @return 是否可以转换
     */
    public boolean change(PermitStatus to){
        switch (this.value) {
            case 0:
                if (to.equals(ADUITING)|| to.equals(DART)) {
                    return true;
                }
                break;
            case 1:
                if (to.equals(REJECT) || to.equals(PUBLISHED)) {
                    return true;
                }
                break;
            case 2:
                if (to.equals(DART) || to.equals(ADUITING)) {
                    return true;
                }
                break;
            case 3:
                return false;
            default:
                return false;
        }
        return false;
    }
}
